package com.zw.hrm.web.controller;

import com.zw.hrm.service.IVerifyCodeService;
import com.zw.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    @PostMapping("/imageCode/{imageCodeKey}")
    public String imageCode(@PathVariable("imageCodeKey") String imageCodeKey) {
        try {
            return verifyCodeService.createImageCodeKey(imageCodeKey);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> map) {
        try {
            verifyCodeService.sendSmsCode(map);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("发送短信失败" + e.getMessage());
        }
    }
}
